﻿using System;
using System.Collections.Generic;
using Orchard;
using Orchard.Environment.Extensions;
using Nwazet.Commerce.Services;

namespace Rework.CommerceHistory.Services {
    [OrchardFeature("Rework.CommercePayPal")]
    public class UserNameCartInfoProvider : IExtraCartInfoProvider {
        private readonly IWorkContextAccessor _workContextAccessor;

        public UserNameCartInfoProvider(IWorkContextAccessor workContextAccessor) {
            _workContextAccessor = workContextAccessor;
        }

        public IEnumerable<string> GetExtraCartInfo() {
            var ctx = _workContextAccessor.GetContext().HttpContext;
            if (ctx != null) {
                if (ctx.User.Identity.IsAuthenticated) {
                    var userName = ctx.User.Identity.Name;
                    if (!string.IsNullOrEmpty(userName)) {
                        return new[] { "UserName: " + userName };
                    }
                }
            }
            return new string[] {};
        }
    }
}
